local zuilun = fk.CreateSkill{
  name = "wk_heg__zuilun",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["wk_heg__zuilun"] = "罪论",
  [":wk_heg__zuilun"] = "锁定技，结束阶段，你亮出牌堆底三张牌，你对自己使用其中的伤害类牌并获得其中的非伤害类牌。",

  ["$wk_heg__zuilun1"] = "吾有三罪，未能除黄皓、制伯约、守国土。",
  ["$wk_heg__zuilun2"] = "唉，数罪当论，吾愧对先帝恩惠。",
}

zuilun:addEffect(fk.EventPhaseStart, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(zuilun.name) and target == player and player.phase == Player.Finish
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local dp_cards = room.draw_pile
    local x = #dp_cards
    if x < 3 then
      room:shuffleDrawPile() 
    end
    local id
    local card
    local to_have = {}
    local to_use = {}
    for i = 1, 3, 1 do
      id = dp_cards[x+1-i]
      card = Fk:getCardById(id, true)
      if card.is_damage_card then
        table.insert(to_use, id)
      else
        table.insert(to_have, id)
      end
    end

    room:turnOverCardsFromDrawPile(player, to_use, zuilun.name)
    local now_use
    repeat
      now_use = table.filter(to_use, function(cid)
        if room:getCardArea(cid) ~= Card.Processing then return false end
        card = Fk:getCardById(cid, true)
        return not player:prohibitUse(card)
      end)
      if #now_use == 0 then break end
      room:useCard{
        card = Fk:getCardById(now_use[1], true),
        from = player,
        tos = { player },
        extraUse = true,
      }
    until player.dead

    if not player.dead and #to_have > 0 then
      room:turnOverCardsFromDrawPile(player, to_have, zuilun.name)
      room:obtainCard(player, to_have, false, fk.ReasonPrey)
    end
  end,
})

return zuilun